// 第一题：写一个myInterval(fn,a , b, n),
// 每次间隔a, a+b, a+2b...a+nb的时间执行fn函数，执行n次欧关闭定时器
 function myInterval(fn, a, b, n) {
     this.a = a;
     this.b = b;
     this.fn = fn;
     this.count = 1;
     this.n = n;
 }
// 正确实现
myInterval.prototype.start = function() {
    let delay = this.a + this.count * this.b;
    let timer = setTimeout(() => {
        console.log('执行函数：', this.count);
        this.fn();
        this.count++;
        this.start();
    }, delay);
    if (this.count > this.n) {
        clearTimeout(timer);
        console.log('清理定时器');
        return;
    };
};

 let instance = new myInterval(function(){
     console.log('执行了。。');
 }, 1000, 2000, 3);
 instance.start();

  //  错误实现
//  myInterval.prototype.start = function() {
//      let time  = this.a;
//      let timer = setInterval(() => {
//          if (this.count > this.n) {
//              clearInterval(timer);
//             return;
//          };
//         this.count ++;
//         this.fn();
//         time = this.a + this.count * this.b;
//         console.log('time:', time, this.count);
//      }, time);
//  };
